﻿#include "xiancheng.h"


void gengxinThread::run()
{
  // 在这个例子中，当线程运行时，它会发射一个信号
    while (1) {
        msleep(200);

        updatetreeWidget();
        //std::cout<<"666666"<<std::endl;

        emit gengxin();

    }

}

void gengxinThread::updatetreeWidget() //动态更新扫描到的值 有问题
{

    //QMessageBox::information(NULL,"提示",item->text(0));
    HANDLE handleexe = OpenProcess(PROCESS_ALL_ACCESS,false,recveshuju->processID);

    if(handleexe==NULL){
          std::cout<<"shibai"<<std::endl;
    }else{
        //std::cout<<lianbiao<<std::endl;
        int size_du;

        switch (recveshuju->xuhao) {
        case 0:
            size_du = 4;//4字节
            break;
        case 1:
            size_du = 1;//单字节
            break;
        case 2:
            size_du = 2;//2字节
            break;
        case 3:
            size_du = 8;//8字节
            break;
        case 4:
            size_du = 4;//单浮点
            break;
        case 5:
            size_du = 8;//双浮点
            break;
        case 6:
            size_du = 4;//字符串
            break;
        default:
            size_du =0;
            break;
        }
        //std::cout<<size_du<<std::endl;
        char* date[8];
        BOOL pid_bol;

        //std::cout<<recveshuju->lianbiao->lianbiaogeshu<<std::endl;

        //if(recveshuju->lianbiao->lianbiaogeshu<=100){
        if(recveshuju->lianbiao->lianbiaogeshu!=0){
            //std::cout<<"1"<<std::endl;
            int i=0;
            for (Node* ahead=(Node*)recveshuju->lianbiao->returnhead();(ahead!=nullptr)&&(i<10000);ahead = ahead->next ) {

                //std::cout<<"xiaooooo"<<std::endl;
                i++;

                pid_bol = ReadProcessMemory(handleexe, (LPVOID)ahead->dizhiaddress, &date, size_du, NULL);

                if (pid_bol == FALSE)
                {
                      // QMessageBox::information(NULL,"警告","读取进程失败");
                       break;
                  }
                   else
                {
                    switch (recveshuju->xuhao) {
                    case 0:
                    {
                        int *k =nullptr;
                        k=(int*)&ahead->value;
                        if((*k)!=*(int*)date)
                            *k = *(int*)date;
                        break;
                    }
                    case 1:
                    {
                        char *k =nullptr;
                        k=(char*)&ahead->value;
                        if(*k!=*(char*)date)
                            *k = *(char*)date;
                        break;
                    }
                    case 2:
                    {
                        wchar_t *k =nullptr;
                        k=(wchar_t*)&ahead->value;
                        if(*k!=*(wchar_t*)date)
                            *k = *(wchar_t*)date;
                        break;
                    }
                    case 3:
                    {
                        unsigned long long *k =nullptr;
                        k=&ahead->value;
                        if(*k!=*(unsigned long long*)date)
                            *k = *(unsigned long long*)date;
                        break;
                    }
                    case 4:
                    {
                        float *k =nullptr;
                        k=(float*)&ahead->value;
                        if(*k!=*(float*)date)
                            *k = *(float*)date;
                        break;
                    }
                    case 5:
                    {
                        double *k =nullptr;
                        k=(double*)&ahead->value;
                        if((*k)!=*(double*)date)
                            *k = *(double*)date;
                        break;
                    }
                    case 6://待定
                    {
                        int *k =nullptr;
                        k=(int*)&ahead->value;
                        if(*k!=*(int*)date)
                            *k = *(int*)date;
                        break;
                    }
                    }

                }
            }

        }

        CloseHandle(handleexe);
        //std::cout << "oo" << std::endl;
    }

}

